<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib  prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib  prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<c:set var="htmlPath" value="${redis:getSysConfig('in_path_html')}"/>
<c:set var="defaultImg" value="${redis:getSysConfig('website_default_img')}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>已经配货订单信息</title>
    <jsp:include page="../../util/import.jsp"/>
    <script type="text/javascript">
        $(function(){
            var $tt = $("#tt").bootstrapTable({
                url: '${basePath}/back/orders/ordersList.sjson',         	/**请求后台的URL（*）**/
                method: 'post',                       	/**请求方式（*）**/
                contentType: "application/x-www-form-urlencoded",
                dataType: 'json',
                toolbar: '#toolbar',               	    /**工具按钮用哪个容器**/
                striped: true,                      	/**是否显示行间隔色**/
                cache: false,                       	/**是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）**/
                pagination: true,                   	/**是否显示分页（*）**/
                sortable: false,                    	/**是否启用排序**/
                sortOrder: 'asc',                   	/**排序方式**/
                queryParamsType: '',
                sidePagination: 'server',           	/**分页方式：client客户端分页，server服务端分页（*）**/
                pageNumber: 1,
                pageSize:10,							/**初始化加载第一页，默认第一页**/
                pageList: [5,10, 25, 50],        	    /**可供选择的每页的行数（*）**/
                search: false,                       	/**是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大**/
                strictSearch: true,
                showColumns: true,                  	/**是否显示所有的列**/
                showRefresh: true,                  	/**是否显示刷新按钮**/
                minimumCountColumns: 2,             	/**最少允许的列数**/
                clickToSelect: true,                	/**是否启用点击选中行**/
                uniqueId: 'ordersId',                  /**每一行的唯一标识，一般为主键列**/
                singleSelect  : true,                   /** 单选checkbox**/
                showToggle:false,                    	/**是否显示详细视图和列表视图的切换按钮**/
                cardView: false,                    	/**是否显示详细视图**/
                detailView: false,                  	/**是否显示父子表**/
                columns: [
                    {checkbox: true},
                    {field: 'Number', title: '编号', align: 'center', valign: 'middle', width: '50px',
                        formatter: function (value, row, index) {
                            var page = $tt.bootstrapTable("getPage");
                            return page.pageSize * (page.pageNumber - 1) + index + 1;
                        }
                    },
                    {field: 'ordersNo', title: '订单号', align: 'center', valign: 'middle',
                        formatter: function (value, row, index) {
                            var a_html = '<a data-toggle="modal" data-target="#detailModal" href="#" mce_href="#" onclick="detailInfo(' + row.ordersId + ')">' + value + '</a>';
                            return a_html;
                        }
                    },
                    {field: "loginName", title: "会员名称", align: 'center', valign: 'middle'},
                    {field: "shopName", title: "店铺名称", align: 'center', valign: 'middle'},
                    {field: "shopInfoType", title: "店铺类型", align: 'center', valign: 'middle',formatter:function(value,rowData,rowIndex){
                        if(value==1){
                            return"自营店铺";
                        }else if(value==2){
                            return"入驻店铺";
                        }
                    }},
                    {field: "consignee", title: "收货人姓名", align: 'center', valign: 'middle'},
                    {field: "finalAmount", title: "应付金额(元)", align: 'center', valign: 'middle'},
                    {field: "settlementStatus", title: "付款状态", align: 'center', valign: 'middle',formatter:function(value,rowData,rowIndex){
                        if(value==0){
                            return"<font class='color_002'>未付款</font>";
                        }else if(value==1){
                            return"<font class='color_001'>已付款</font>";
                        }
                    }},
                    {field: "orderSource", title: "订单来源", align: 'center', valign: 'middle',formatter:function(value,rowData,rowIndex){
                        if(value==1){
                            return"正常购物pc下单";
                        }else if(value==2){
                            return"pc团购下单";
                        }else if(value==3){
                            return"手机web下单";
                        }else if(value==4){
                            return"手机团购下单";
                        }else if(value==5){
                            return"微信下单";
                        }else if(value==6){
                            return"微信团购下单";
                        }else if(value==7){
                            return"APP IOS下单";
                        }else if(value==8){
                            return"APP ANDROID下单";
                        }else if(value==9){
                            return"抢购PC下单";
                        }else if(value==10){
                            return"抢购PHONE下单";
                        }else if(value==11){
                            return"抢购微信下单";
                        }else if(value==12){
                            return"抢购APP下单";
                        }else if(value==13){
                            return"组合购PC下单";
                        }else if(value==14){
                            return"组合购PHONE下单";
                        }else if(value==15){
                            return"组合购微信下单";
                        }else if(value==16){
                            return"组合购APP下单";
                        }else if(value==17){
                            return"积分商城PC下单";
                        }else if(value==18){
                            return"积分商城PHONE下单";
                        }else if(value==19){
                            return"积分商城微信下单";
                        }else if(value==20){
                            return"积分商城APP下单";
                        }
                    }
                    },
                    {field: "ordersState", title: "订单状态", align: 'center', valign: 'middle',formatter:function(value,rowData,rowIndex){
                        if(value==0){
                            return"生成订单";
                        }else if(value==3){
                            return"正在配货";
                        }else if(value==4){
                            return"已发货";
                        }else if(value==5){
                            return"待评价";
                        }else if(value==6){
                            return"已取消";
                        }else if(value==7){
                            return"异常订单";
                        }else if(value==1){
                            return"<font class='color_002'>未付款</font>";
                        }else if(value==9){
                            return"已评价";
                        }
                    }
                    },
                    {field: "createTime", title: "订单生成时间", align: 'center', valign: 'middle', formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        return toJsonDate(value,"yyyy-MM-dd hh:mm:ss");
                    }},
                    {field: "updateTime", title: "订单配货时间", align: 'center', valign: 'middle', formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        return toJsonDate(value,"yyyy-MM-dd hh:mm:ss");
                    }}
                ],
                queryParams: function (params) {
                    /**特别说明，返回的参数的值为空，则当前参数不会发送到服务器端,这种指定请求参数的方式和datatables控价类似**/
                    params.ordersNo = $("#q_ordersNo").val();
                    params.shopInfoType = $("#q_shopInfoType").val();
                    params.orderSource = $("#q_orderSource").val();
                    params.orderState = 3;
                    params.currentPage = params.pageNumber;
                    return params;
                }
            });
        });

        /**
		 * 查看订单商品
		 */
		<shiro:hasPermission name="back_gotoWaitShipmentsOrdersPage_orderProduct">
        function orderProduct(){
            var selectedRow = $("#tt").bootstrapTable('getSelections');
            if(selectedRow.length==1){
                var ordersNo=selectedRow[0].ordersNo;
                $("#btn_orderProduct").attr("data-target","#view_Order_Products_Modal");
                $.ajax({
                    type: "POST",
                    dataType: "JSON",
                    url: "${basePath}/back/orders/findOrdersProduct.sjson",
                    data: {ordersNo:ordersNo},
                    success: function(result){
                        var data = JSON.parse(result.data);
                        var productMap = data.productMap;
                        var html="<tr class='titlebg'>" +
                            "<td align='center' colspan='13'> 订单号："+data.orderNo+"</td>" +
                            "</tr>";
                        html += "<tr>" +
                            "<td align='center' width='150px'>图片</td>" +
                            "<td align='center' width='150px'>商品名称</td>" +
                            "<td align='center' width='150px'>销售价</td>" +
                            "<td align='center' width='150px'>数量</td>" +
                            "<td align='center' width='150px'>运费</td>"+
                            "<td align='center' width='150px'>折扣</td>" +
                            "<td align='center' width='150px'>赠送金币</td>" +
                            "<td align='center' width='150px'>返利比例(一级)</td>" +
                            "<td align='center' width='150px'>返利比例(二级)</td>" +
                            "<td align='center' width='150px'>返利比例(三级)</td>" +
                            "<td align='center' width='150px'>返利金额(一级)</td>" +
                            "<td align='center' width='150px'>返利金额(二级)</td>" +
                            "<td align='center' width='150px'>返利金额(三级)</td>" +
                            "</tr>";
                        for(var i=0;i<productMap.length;i++){
                            var zk = productMap[i].discount;
                            if(zk == null){
                                zk = "无折扣";
                            }else{
                                zk += "折";
                            }
                            var virtualCoinNumber=productMap[i].virtualCoinNumber;
                            var salesPrice=productMap[i].salesPrice;
                            var freightPrice=productMap[i].freightPrice;
                            /**返利信息**/
                            var upRatio=productMap[i].upRatio;
                            var secRatio=productMap[i].secRatio;
                            var thiRatio=productMap[i].thiRatio;
                            var upRatioAmount=productMap[i].upRatioAmount;
                            var secRatioAmount=productMap[i].secRatioAmount;
                            var thiRatioAmount=productMap[i].thiRatioAmount;
                            if(virtualCoinNumber==null || virtualCoinNumber==""){
                                virtualCoinNumber=0;
                            }
                            if(salesPrice==null || salesPrice==""){
                                salesPrice=0;
                            }
                            if(freightPrice==null || freightPrice==""){
                                freightPrice=0;
                            }
                            html+="<tr>" +
                                "<td align='center' width='85px'><img width='80px' height='50px' src='"+"${uploadPath}/"+productMap[i].logoImage+"' onerror='this.src=\"${srcPath}productInfo/images/mrbj.png\"'/></td>" +
                                "<td align='center' width='120px'>"+productMap[i].productFullName+"</td>" +
                                "<td align='center' width='50px'>"+salesPrice+" 元"+"</td>" +
                                "<td align='center' width='150px'>"+productMap[i].count+"</td>" +
                                "<td align='center' width='50px'>"+freightPrice+" 元"+"</td>" +
                                "<td align='center' width='50px'>"+zk+"</td><td align='center' width='50px'>"+virtualCoinNumber+" 个"+"</td><td align='center' width='50px'>"+upRatio+"%"+"</td><td align='center' width='50px'>"+secRatio+"%"+"</td><td align='center' width='50px'>"+thiRatio+"%"+"</td><td align='center' width='50px'>"+upRatioAmount+"元"+"</td><td align='center' width='50px'>"+secRatioAmount+" 元"+"</td><td align='center' width='50px'>"+upRatioAmount+" 元"+"</td></tr>";
                        }
                        $("#Order_Products").html(html);
                    }
                });
            }else{
                $("#btn_orderProduct").attr("data-target","");
                showMsg("请选择一行记录！");
            }
        }
		</shiro:hasPermission>

		/**
		 * 发货
		 */
		<shiro:hasPermission name="back_gotoWaitShipmentsOrdersPage_delivery">
        function delivery(){
            var selectedRow = $("#tt").bootstrapTable('getSelections');
            if(selectedRow.length==1){
                $("#mySendGoodsModalLabel").empty().text("订单发货");
                if(selectedRow[0].sendType==1){
                    $("#type1").css("display","");
                    $("#type2").css("display","none");
				}else if(selectedRow[0].sendType==2){
                    $("#type1").css("display","none");
                    $("#type2").css("display","");
                    $("#cityCourier").html("");
				}
				if(selectedRow[0].sendType!=3){ /**不是线下自取**/
                    $("#ordersId_shipping").val(selectedRow[0].ordersId);/**给隐藏域赋值**/
                    $("#ordersId_cityCourier").val(selectedRow[0].ordersId);/**给隐藏域赋值**/
                    /**清空同城物流table信息 **/
                    $("#province").val("");
                    $("#cities").val("");
                    $("#district").val("");
                    $("#cityCourier").val("");
                    /**清空同城物流table信息 **/
                    /**清空物流公司table信息 **/
                    $("#deliverySn").val("");
                    $(".combo-text").val("");
                    /**清空物流公司table信息 **/
                    $("#codeError").val("");
                    $("#cityCourierError").val("");
                    $("#btn_delivery").attr("data-target","#sendGoodsModal");
                    $("#logisticsType").val(selectedRow[0].sendType);
				}else{
                    $("#btn_delivery").attr("data-target","");
				    var ordersId=selectedRow[0].ordersId;
                    showConfirm("该商品是线下自取，是否确认发货?", function() {
                        var logisticsType=3;
                        $.ajax({
                            type: "POST",dataType: "JSON",
                            url: "${basePath}/back/orders/changeShipments.sjson",
                            data: {logisticsType:logisticsType,ordersId:ordersId},
                            success: function(data){
                                if(data.success==true){
                                    $("#tt").bootstrapTable('refresh');
                                }
                            }
                        });
                    });
				}
            }else{
                showMsg("请选择一行记录！");
			}
		}
		</shiro:hasPermission>

	</script>
	</head>
	<body>
	<div class="panel-body" id="customer-main-panel">
		<!-- 查询条件 -->
		<div class="panel panel-default">
			<div class="panel-heading">已配货订单查询</div>
			<div class="panel-body">
				<form id="qform" class="form-horizontal">
					<div class="form-group" style="margin-top:15px">
						<div class="col-sm-3">
							<div class="input-group input-group-sm">
								<span class="input-group-addon">订单号</span>
								<input type="text" class="form-control" id="q_ordersNo" name="name" placeholder="请输入名称"/>
							</div>
						</div>
						<div class="col-sm-3" style="width:258px;">
							<div class="input-group input-group-sm">
								<span class="input-group-addon">店铺类型</span>
								<select id="q_shopInfoType" class="form-control">
									<option value="">--请选择--</option>
									<option value="1">自营店铺</option>
									<option value="2">入驻店铺</option>
								</select>
							</div>
						</div>
						<div class="col-sm-3" style="width:258px;">
							<div class="input-group input-group-sm">
								<span class="input-group-addon">订单来源</span>
								<select id="q_orderSource" class="form-control">
									<option value="">--请选择--</option>
									<option value="1">正常购物pc下单</option>
									<option value="2">pc团购下单</option>
									<option value="3">手机web下单</option>
									<option value="4">手机团购下单</option>
									<option value="5">微信下单</option>
									<option value="6">微信团购下单</option>
									<option value="7">APP IOS下单</option>
									<option value="8">APP ANDROID下单</option>
									<option value="9">抢购PC下单</option>
									<option value="10">抢购PHONE下单</option>
									<option value="11">抢购微信下单</option>
									<option value="12">抢购APP下单</option>
									<option value="13">组合购PC下单</option>
									<option value="14">组合购PHONE下单</option>
									<option value="15">组合购微信下单</option>
									<option value="16">组合购APP下单</option>
									<option value="17">积分商城PC下单</option>
									<option value="18">积分商城PHONE下单</option>
									<option value="19">积分商城微信下单</option>
									<option value="20">积分商城APP下单</option>
								</select>
							</div>
						</div>
						<div class="col-sm-2">
							<button type="button" id="btn_query" class="btn btn-primary">查询</button>&nbsp;&nbsp;
							<button type="reset" class="btn btn-success" id="resetBtn">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>

		<!-- 工具栏 -->
		<div id="toolbar" class="btn-group">
			<shiro:hasPermission name="back_gotoWaitShipmentsOrdersPage_orderProduct">
				<button id="btn_orderProduct" type="button" class="btn btn-default" data-toggle="modal" onclick="orderProduct()">
					<span class="glyphicon glyphicon-search" aria-hidden="true"></span>查看订单商品
				</button>
			</shiro:hasPermission>

			<button id="btn_ordersOpLog" type="button" class="btn btn-default" data-toggle="modal" onclick="oplog()">
				<span class="glyphicon glyphicon-search" aria-hidden="true"></span>查看订单日志
			</button>

			<shiro:hasPermission name="back_gotoWaitShipmentsOrdersPage_delivery">
				<button id="btn_delivery" type="button" class="btn btn-default" data-toggle="modal" onclick="delivery()">
					<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>发货
				</button>
			</shiro:hasPermission>
		</div>

		<!-- 渲染的table -->
		<table id="tt"></table>
		<jsp:include page="view_Order_Products.jsp"/>
		<jsp:include page="sendGoods.jsp"/>
		<jsp:include page="detailOrders.jsp"/>
		<jsp:include page="detailOrderOPLog.jsp"/>
	</div>
	</body>
</html>
